#include "monitor.h"

#include <QApplication>
#include <QSharedMemory>
#include <QFile>
#include <QTextCodec>
#include <QWebEngineSettings>
#include <QThreadPool>

int main(int argc, char *argv[])
{
    // QWebEngine硬件加速
    qputenv("QT_D3D_ADAPTER_INDEX", "0");        // 指定主显卡（可选）
    QApplication::setAttribute(Qt::AA_UseDesktopOpenGL);    //使用纯 OpenGL（非 ANGLE）
    //QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL, false);

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

    QApplication a(argc, argv);

    QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
    qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-gpu");

    // 注册 WId 类型
    qRegisterMetaType<WId>("WId");
    //中文显示乱码问题
    QTextCodec *codec = QTextCodec::codecForName("utf-8");
    QTextCodec::setCodecForLocale(codec);

    QFont f("Microsoft YaHei", 12, QFont::Normal);
    a.setFont(f);

    //加载样式表
    QApplication::setStyle(QStyleFactory::create("Fusion"));
    QFile styfile(":/monitor.qss");
    if (styfile.open(QFile::ReadOnly)) {
        QString styQss = QLatin1String(styfile.readAll());
        qApp->setStyleSheet(styQss);
        styfile.close();
    }

    //防止程序多开
    QSharedMemory singleton(a.applicationName());
    if(!singleton.create(1))
        return 0;

    Monitor w;
    w.show();
    return a.exec();
}
